
require "Json"

local socket = require("socket")
local client, m = socket.connect("localhost", 8173)

if m then
	error(m)
end

client:send('json\n')

while true do
	local s = client:receive('*l')
	if not s then
		return
	end
	local object = Json.Decode(s)
	if type(object) == 'table' then
		if object.Info then
			local src = object.Info.short_src
			--local src = object.Info.source
			local line = object.Info.currentline
			print(src .. ': ' .. line)
		elseif object.Locals then
			local Locals = object.Locals
			for i, p in ipairs(Locals) do
				print(p[1])
				print(p[2])
			end
		end
	else
		print(object)
	end
	io.write('>')
	io.flush()
	local op = io.read()
	local BreakPoints = {
		{File = '@expr.lua', Line = 11, Type = 'Line'},
	}
	local Op = { Op = op, BreakPoints = BreakPoints }
	if op == 'r' then
		Op.Mode = 'r'
		Op.Op = 'l'
	elseif op == 'w' then
		Op.Mode = 'w'
	end
	s = Json.Encode(Op)
	client:send(s..'\n')
end

